/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-19 17:44:42
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-20 08:12:08
 */
import 'package:flutter_data_center/model/alert/alert_model.dart';
import 'package:flutter_data_center/model/common/menu_model.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class AlertController extends GetxController {
  int _camera = 0;
  int get camera => _camera;
  int _error = 0;
  int get error => _error;
  int _network = 0;
  int get network => _network;
  void getAlertStatistics() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.alertStatistics,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _camera = data['camera'];
      _error = data['error'];
      _network = data['network'];
      update();
    }
  }

  List<AlertModel> _list = [];
  List<AlertModel> get list => _list;
  void getAlerts() async {
    _list = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.alertList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _list.add(AlertModel.fromJson(item));
      }
      update();
    }
  }

  // 菜单
  List<MenuModel> _menus = [
    MenuModel("全部", "all"),
    MenuModel("监控", "camera"),
    MenuModel("故障", "error"),
    MenuModel("网络", "network"),
  ];
  List<MenuModel> get menus => _menus;
}
